#!/usr/bin/perl
use strict;
use DBI;

my $db = "DBI:Oracle:host=192.158.127.197;port=1521";
my $userName = "drw";
my $passWord = "drw";
my $dbh = DBI->connect( $db, $userName, $passWord )
  or die "Can't connect\n";
  
  
print "connect successfully.\n";

my $sql = "SELECT * FROM favorite f";
my $sth = $dbh->prepare($sql);

print "=====dump results======\n";
$sth->execute();
print qq(\n\tContents of "favorite" table\n);
$sth->dump_results();

print "\n\n=====fetch a row as an array======\n";
$sth->execute();
while ( my @row = $sth->fetchrow_array() )
{
	for (my $i=0; $i < @row; $i++)
	{
		print $row[$i], ", ";
	}
	print "\n";
}
print $sth->rows(), " rows were retrieved.\n";

print "\n\n=====fetch a row as an hash======\n";
$sth->execute();
while ( my $row = $sth->fetchrow_hashref() )
{
	while ( my ($key, $value) = each %$row )
	{
		print "$key => $value", ", ";
	}
	
	print "\n";
}

$sth->finish(); 
$dbh->disconnect();